<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['diy']=$this->plugin_setting('diy');
$basic=$this->plugin_setting('basic');
$return['basic']=$basic;
$return['banner']=$basic['hdps'];
$this->session('type',$_RQ['type']);
if($_RQ['type']){
	$this->session('type',$_RQ['type']);
}
if($_RQ['op']=='main'){
	$isgochat=$this->session('isgochat0');
	$isadd=$this->model('model')->check_isaddqun();
	if(!$isadd && !$isgochat){
		exi('','','/gochat//id=0');
	}
	if($_RQ['type']=='work'){
		$this->model('model')->checkvip();
	}
	$return['notices']=pdo_getall('core_account_article',array('uniacid'=>$_SESSION['uniacid'],'status'=>'1'),'','id desc');
	set_html('title','用户列表');
	$return['sharedata']=array(
		'title'=>$basic['share_title'],
		'desc'=>$basic['share_desc'],
		'link'=>custom_url('jy_kecheng/userlist/',true),
		'imgUrl'=>ATTACHMENT_URL.$basic['share_image'],
	);
	$return['params']=array('page'=>1,'keyword'=>'');
	if($_RQ['keyword']){
		$return['params']['keyword']=$_RQ['keyword'];
	}
	//是否关注
	$return['isfollow']=pdo_getcolumn('core_fans',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'follow');
	exi($return);
}
if($_RQ['op']=='getlist'){
	$type=$this->session('type');
	$return['params']=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);	
	}
	if($_RQ['keyword']){
		if(is_numeric($_RQ['keyword'])){
			$params['id']=intval($_RQ['keyword']);
		}else{
			$params['realname like']='%'.$_RQ['keyword'].'%';
		}
		$return['params']['keyword']=$_RQ['keyword'];		
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$list=pdo_getslice('jy_kecheng_user',$params,array($pindex,$psize),$total,$fields,'','updatetime desc');
	foreach($list as &$kv){
		$kv['thumb']=tomedia($kv['thumb']);
	}	
	//按点赞数排序作品
	if($list){
		$sum=count($list);
		foreach($list as &$item){
			$item['updatetime']=$item['updatetime']?:$item['createtime'];
			$item['createtime']=date('Y-m-d H:i:s',$item['createtime']);
			$item['thumb']=tomedia($item['avatar']);
			$lasttime=TIMESTAMP-$item['updatetime'];
			if($lasttime>24*3600){
				$item['updatetimetitle']=intval($lasttime/24*3600).'天前';
			}elseif($lasttime>=3600){
				$item['updatetimetitle']=intval($lasttime/3600).'小时前';
			}else{
				$item['updatetimetitle']=intval($lasttime/60).'分钟前';
			}
			$quan_log=pdo_get('jy_kecheng_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'userid'=>$item['id']));
			if($quan_log['id']){
				if($quan_log['isfollow']==1){
					$item['islook']=2;
				}else{
					$item['islook']=1;
				}
			}
			
		}
	}
	$return['list']=$list;
	$return['params']['page'] =$pindex;
	exi($return);
}
if($_RQ['op']=='looklog'){
	$userid=intval($_RQ['id']);
	$quan_log=pdo_get('jy_kecheng_userlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'userid'=>$userid));
	if(!$quan_log['id']){
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'userid'=>$userid,
			'createtime'=>TIMESTAMP
		);
		pdo_insert('jy_kecheng_userlog',$insert);		
	}	
	exi('success');
}